from random import choice


class RandomWalk():
    """
    choice([随机数])
    """
    def __init__(self, max_walk = 5000):
        self.max_walk = max_walk

        # 所有随机点都起始于（0， 0）
        self.start_x = [0]
        self.start_y = [0]

    def walk(self):

        # 小于max_walk，一直漫步
        while len(self.start_x) < self.max_walk:
            # 确定方向和行走的距离
            x_direction = choice([1, -1])
            x_distance = choice([0, 1, 2, 3, 4])
            x_step = x_direction * x_distance

            y_direction = choice([1, -1])
            y_distance = choice([0, 1, 2, 3, 4])
            y_step = y_direction * y_distance

            # 禁止原地踏步
            if x_step == 0 and y_step == 0:
                continue

            # 确定下一个点的坐标
            next_x = self.start_x[-1] + x_step
            next_y = self.start_y[-1] + y_step

            # 保存x、y的位置点坐标
            self.start_x.append(next_x)
            self.start_y.append(next_y)

